<!--
 * @Author: 邵朋 
 * @Date: 2023-12-08 19:19:11
 * @LastEditors: shaopeng 852118459@qq.com
 * @LastEditTime: 2024-04-22 17:44:33
 * @FilePath: /YouDian/src/pages/index/index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
	<view class="container d-flex-column a-center">
		<view class="bg"></view>
		<view class="content d-flex-column ">
				<view class="add-content d-flex j-end" >
					<view class="add-btn d-flex j-center a-center" @click="msgAction">
						<image
							class="add"
							:src="icon.msg"
							mode="aspectFit"
							></image>
					</view> 
					<view class="add-btn d-flex j-center a-center" @click="addAction">
						<image
							class="add"
							:src="icon.add"
							mode="aspectFit"
							></image>
					</view>
					
					
				</view>
	
			<view class="tp d-flex a-center">
				<image
				class="avatar"
				:src="isLogin ? user.head_Portrait : icon.defaulthead"
				mode="aspectFit"
				@click="editAction"
				></image>
				<view class="tp-info d-flex a-center" v-if="!isLogin" @click="loginAction">
					<view class="login-name">去登录</view>
					<image
						class="login-arrow"
						:src="icon.arrow"
						mode="aspectFit"
					></image>
				</view>

				 <view class="tp-info d-flex-column" v-if="isLogin" @click="editAction">
					<view class="tp-name-content d-flex a-center">
						<view class="user-name text-black"  >{{ user.nickName }}</view>
						<!-- <view class="edit-btn d-flex a-center j-center">
							<image
							class="edit"
							:src="icon.edit"
							mode="aspectFit"
							
							></image>
						</view> -->
						
					</view>
					<view class="machine-count">{{ list.length }}个设备</view>
				 </view>
			</view>
			<view class="warn-content d-flex a-center j-sb" v-if="!isCloseWarningTips && (waringTipsMsg !== '' && waringTipsMsg !== null)">
				<view class="warn-text"  @click="msgAction">{{ waringTipsMsg }}</view>
				<view class="close-btn d-flex a-center" @click="closeWarnMsgAction">
						<image
						class="close"
						:src="icon.close"
						mode="aspectFit"
						></image>
					</view>
			</view>
			<view class="mid bg-white d-flex-column w-100" v-if="(!isCloseWarningTips && (waringTipsMsg !== '' && waringTipsMsg !== null)) ? false : (!isCloseCompanyView && isHasCompanyDesc)" >
                 <view class="mid-tp d-flex w-100 j-sb a-center">
					<view class="company-name font-weight-bold text-black">{{ company.companyName }}</view>
					<view class="close-btn d-flex a-center" @click="closeCompanyAction">
						<image
						class="close"
						:src="icon.close"
						mode="aspectFit"
						></image>
					</view>
				 </view>
				 <!-- <view class="company-desc">{{ company.companyDesc }}</view> -->

				  <view class="company-desc">
					<text id="qyjs" class="company-desc-text qyjs" :class="{ showAllQyjs: showAll == false }">{{ company.companyDesc
						}}</text>
					<!-- 展开收起按钮 -->
					<view class="label showAll" @click="showinfo" v-if="(company !== null && company.companyDesc !== null &&company.companyDesc.length > 150)">
						{{ showAll ? '收起' : '查看更多' }}
						<image
						class="pullicon"
							:src="showAll ? icon.pullup : icon.pulldown"
							mode="aspectFit"
						/>
					</view>
				</view>

			</view>
			<view class="bt d-flex-column w-100" :class="isCloseCompanyView || !isHasCompanyDesc ? 'mt-80' : 'mt-20'">
				<view class="section text-black font-20 font-weight-bold">设备列表</view>
				<view class="no-data-voew w-100 d-flex-column a-center" v-if="list === null || list.length === 0">
					<image class="no-data-icon" :src="icon.nodata" mode="aspect"></image>
					<view class="font-12 mt-15 tips-text">没有任何设备</view>
					<view class="font-12 mt-5 tips-text d-flex a-center"  @click="addAction">请先
						<view class="text-theme font-weight-bold">添加设备</view>
					</view>

				</view>
				<view class="list d-flex flex-wrap w-100"  v-if="list.length !== 0">
					<view class="item bg-white d-flex-column" :data-id="index" :class="index%2===0 ? 'item-left' : 'item-right'" v-for="(item,index) in list" :key="index" @click="clickDetail">
					<!-- <view class="item bg-white d-flex-column" :data-id="index" :class="index%2===0 ? 'item-left' : 'item-right'" v-for="(item,index) in list" :key="index" @click="clickDetail(item)" @longpress="longTapEquip"> -->
						<view class="item-tp w-100 d-flex a-center j-sb" :data-id="index">
							<view class="item-name font-weight-bold text-black"  :data-id="index">{{ item.deviceName }}</view>
							<image
								class="connect"
								:src="item.isConnect ? icon.bleconnect :  icon.bleclose"
								mode="aspectFit"
								:data-id="index"
								></image>
						</view>
						<view class="w-100 d-flex a-center j-sb" :data-id="index">
							<view class="status-name"  :data-id="index" :class="item.isConnect ? 'status-green' : 'status-red'">{{ item.isConnect ? '已连接' :  '未连接' }}</view>
							<!-- <view class="tag-name"  :data-id="index">50吨卡车</view> -->

						</view>
						<image
								class="equip-img"
								:data-id="index"
								:src="item.deviceModelImg"
								mode="aspectFit"
								></image>
					</view>
				</view>
			</view>
		</view>

		<view class="rightmask d-flex j-end" v-if="isShowRightPop" @click="hiddenRightNaviPopView">
			<view class="rightpop d-flex-column">
				<view class="right-item" v-for="(item,index) in rightbtnList" :key="index" @click="clickRightNaviItem(item)">{{ item }}</view>
			</view>
		</view>
		<qdxns-pop :height="operateList.length*100" :width="220" :top="60" :left="60" ref="qdxPop">
			<view class="operatelist d-flex-column">
				<view class="operate-item" v-for="(item,index) in operateList" :key="index" @click="clickEquipOperate(item)">{{ item }}</view>
			</view>
		</qdxns-pop>	
		<uni-popup ref="authpopup" type="bottom" :safe-area="false">
			<view class="authpopview d-flex-column">

				<view class="w-100 d-flex j-end mt-20">
					<view class="skip-btn d-flex a-center j-center" @click="notauthAction">
						<image :src="icon.closepop" class="skip" mode="widthFix" ></image>
					</view>
				</view>
				<image :src="icon.logo" class="logo" mode="aspectFit"></image>

				<view class="title">您还未登录</view>
					<view class="slogan">请确认以下授权信息</view>

					<view class="w-100 d-flex j-center">
						<view class="line"></view>
					</view>
				<!-- <div class="needtips">获取你的信息（头像/昵称/手机号等）</div> -->
				<view class="defualt-btn d-flex a-center" >
					<image v-if="isAgree" class="btn-icon" src="@/static/img/icon-sel.png" mode="aspectFit" @click="clickAgreeProtocol"></image>
					<image v-if="isAgree === false" class="btn-icon" src="@/static/img/icon-nor.png" mode="aspectFit" @click="clickAgreeProtocol"></image>

					<view class="btn-name d-flex a-center font-13 flex-wrap">
						我已阅读并同意
						<view class="text-theme" @click="clickProtocol">《有电隐私政策》</view>
					</view>
				</view>

				<view class="btns  d-flex-column a-center">
					

					<view class="auth-btn text-center" @click="authAction">授权登录</view>
					<view class="notauth-btn" @click="notauthAction">暂不登录</view>

				</view>
				</view>
		</uni-popup>
		<uni-popup ref="popup" type="bottom" :safe-area="false">
			<view class="popup">
				<view class="border-bottom">
					<view class="w-100 d-flex j-end mt-20">
						<view class="skip-btn d-flex a-center j-center" @click="hideUpdateUserPopView">
							<image :src="icon.closepop" class="skip" mode="widthFix" ></image>
						</view>
					</view>
					<view class="title text-center font-15">
					邀请您补全个人信息
					</view>
					<view class="text text-center">
					如果已设置，请忽略
					</view>
				</view>
				<view class="info py-10 px-30">
					<view class="label d-flex a-center">
					<view class="name mr-10">
						头像
					</view>
					<view class="d-flex ml-20">
						<button class="headBtn" open-type="chooseAvatar" @chooseavatar="uploadHead">
						<image class="head-pic d-block" mode="widthFix" :src="tmpUser.avatarUrl === '' ? icon.defaulthead  : tmpUser.avatarUrl"></image>
						</button>
					</view>
					</view>
					<view class="label d-flex a-center mt-20">
					<view class="name mr-10">
						昵称
					</view>
					<view class="input-cont d-flex a-center">
						<input class="nickname" type="nickname" placeholder="请输入" maxlength=12 :value="tmpUser.nickName"  @blur="bindblur"/>
					</view>
					</view>
				</view>
				<view class="popbtns d-flex j-space-around a-center">
					<view class="btn cancel-btn" @click="hideUpdateUserPopView">
					取消
					</view>
					<view class="btn save-btn" @click="submitUpdateUserInfo">
					确定
					</view>
				</view>
				</view>

		</uni-popup>
		<view class="guide-mask" v-if="isShowGuide" @click="nextGuideAction">
		    <image
			   v-if="guideIndex === 0"
				class="guide1"
				:src="icon.guide1"
				mode="widthFix"
			/>
			<view v-if="guideIndex === 0" class="guide-tips g-tips1">
			  <view>登录后点击查看头像可维护个人信息</view>
			</view>
			<view v-if="guideIndex === 0" class="guide-btn-con g-btn1 d-flex j-center">
				<view class="guide-btn">我知道了</view>
			</view>
			<image
			   v-if="guideIndex === 1"
				class="guide2"
				:src="icon.guide2"
				mode="widthFix"
			/>
			<view v-if="guideIndex === 1" class="guide-tips g-tips2 d-flex-column a-end">
			   <view>点左边图标查看系统信息</view>
			   <view class="mt-5">点右边图标添加您的设备</view>

			</view>
			<view v-if="guideIndex === 1" class="guide-btn-con g-btn2 d-flex j-center">
				<view class="guide-btn">我知道了</view>
			</view>
			<image
			v-if="guideIndex === 2"

				class="guide3"
				:src="icon.guide3"
				mode="widthFix"
			/>
			<view v-if="guideIndex === 2" class="guide-tips g-tips3 d-flex-column">
			   <!-- <view>未添加设备可在此添加</view> -->
			   <view  class="muklline-2">添加成功的设备显示在这里，点击设备可进行操作</view>

			</view>
			<view v-if="guideIndex === 2" class="guide-btn-con g-btn3 d-flex j-center">
				<view class="guide-btn">我知道了</view>
			</view>
		</view>
	</view>
</template>

<script lang="ts">
    import qdxnsPop from '@/components/qdxns-popup/qdxns-popup.vue';
	import * as router  from '@/util/router/router'
    import * as toast from '@/util/toast/toast'
	import * as btViewmodel from '@/util/bluetoothUtil/btViewmodel'
   import  * as btUtil from '@/util/bluetoothUtil/btUtil'
  import Vue from 'vue';

	export default Vue.extend({
		components: {
			qdxnsPop,
		},
		data() {
			return {
				icon:{
					nodata:require('@/static/img/no_equip.png'),

					logo:require('@/static/img/applogo.png'),
					closepop:require('@/static/img/ic_close_auth.png'),
					defaulthead:require('@/static/img/ic_default_head.png'),
					arrow:require('@/static/img/ic_blue_r.png'),
					add:require('@/static/img/ic_add.png'),
					msg:require('@/static/img/ic_msg.png'),
					edit:require('@/static/img/ic_edit.png'),
					bleconnect:require('@/static/img/ic_ble_connect.png'),
					bleclose:require('@/static/img/ic_ble_disconnect.png'),
					close:require('@/static/img/ic_close_window.png'),
					pulldown:require('@/static/img/ic_down.png'),
					pullup:require('@/static/img/ic_up.png'),
					guide1:require('@/subPackages/static/login_guide_icon.png'),
					guide2:require('@/subPackages/static/add_guide_icon.png'),
					guide3:require('@/subPackages/static/device_guide_icon.png'),

				},
				isLogin:false,
				isCloseCompanyView:false,
				isHasCompanyDesc:false,
				isShowRightPop:false,
				isCloseWarningTips:false,
				waringTipsMsg:'',
				user:{
					nickName:'',
					head_Portrait:'',
				},
				company:{
					companyLogo:'',
					companyName:'',
					companyDesc:'航迪机械是于2004年成立自主品牌的摩托车发动机公司，2011年成立通机公司，2013年成立增程器公司，2020年成立驻车发电机公司；并在驻车发电机行业标新立异不做同质化产品； 航迪机械是驻车发电机行业里首创防燃阻燃的核心主打安全的铁甲款驻车发电机的企业；是首个提出并实现把24V驻车发电机成立为独立工厂的企业；是国内首个开发驻车发电机全系列企业（隐藏款，开架款，白银静音王，黄金静音王，便携式铁甲，便携式手提，铁甲燃气，黄金静音燃气），满足所有卡友各种档次驻车发电机需求。',
				},
				choosedEquip:null as any, ///当前长按选中的设备
				list:[] as any,
				operateList:[] as any,
				rightbtnList:['添加直流电机','添加其他'] as any,
				isAgree:false,
				tmpUser:{
					avatarUrl:'',
					nickName:'',
				},
				showAll: true, //控制展开收起
				lineHeight: 20, //单行文本高度
				textHeight: 0, //文本高度
				placeholder: '占位文本',
                query:null as any,
				isShowGuide:false,///是否展示引导页
				guideIndex:0,
			}
		},
		onLoad() {



			

			let device = uni.getWindowInfo()
            let screenH = device.screenHeight;
			(this as any).$User.screenHeight = screenH;
			(this as any).$User.topSafeArea  = device.safeArea.top ;

			this.isLogin = !(this as any).$User.isNotLogin();
			this.startLocate()
			// this.loadData()

			this.judgeNeedShowGuide()

			// let data = '5A01470001E600020000030004860E00000576770100060000000007000000000800000900000A000800020C000EFF0F80110112000033003401350036E800370138040139F0003A003B02ED0D0A'
			// btUtil.parseBleData(data)

			// btViewmodel.handleDeviceWarningUpload()


			let self = this;
			uni.getNetworkType({
				success: function (res) {
				console.log(res.networkType);
				if (res.networkType === 'none') {
					let msg = '无法连接网络，检查网络设置是否正常。'
					uni.showModal({
						content: msg,
						confirmText:'知道了',
						showCancel:false,
						success: function (res) {
						
						}
					});
				} else {
					self.loadData()
				}
			}});
			


		},
		onShow(){
			this.loadUserInfoReq()

			this.onBleStatsChangedListen()
			if((this as any).$User.isNeedRefreshEquipmentList === true){
				(this as any).$User.isNeedRefreshEquipmentList = false
				this.loadData()

			}else{
				///刷新蓝牙选中状态
				this.refreshListDeviceConnectStatus()
					

			}

			this.loadNewestWarningTipsReq()
		},
		onShareAppMessage: function (res) {
			if (res.from === 'button') {
			// 来自页面内转发按钮
			console.log(res.target)
			}
			return {
			title: '快来跟我一起使用有电用户版本吧~',
			path: '/pages/index/index'
			}
		},
		methods: {
			judgeNeedShowGuide(){
				if((this as any).$User.isNotLogin() === false){
					this.isShowGuide = false
					return
				}

				let isShowedGuide = uni.getStorageSync('isShowedGuide')
				if(isShowedGuide !== '1'){
					this.isShowGuide = true
				}else{
					this.isShowGuide = false
				}
			},
			nextGuideAction(){
				this.guideIndex ++
				if(this.guideIndex > 2){
					this.isShowGuide = false
					uni.setStorageSync('isShowedGuide','1')

				}

			},
			// 展示隐藏查看更多
			showinfo() {
				this.showAll = !this.showAll
			},
			onBleStatsChangedListen(){

				if((this as any).$User.isConnectedBlueTooth === false){
					return
				}

				let self = this;
				uni.onBluetoothAdapterStateChange(function (res) {
					if(res.available === false){
						(self as any).$User.isConnectedBlueTooth = false;
						(self as any).$User.isTempConnectedBlueTooth = false;
						(self as any).$User.currentConnectedEquipment.deviceID = '';
						(self as any).$User.currentConnectedBlueTooth = {} as any
						self.isCloseCompanyView = false;

						self.refreshListDeviceConnectStatus()
					}
				})

			},
			startLocate(){

				if(this.isLogin === false){
					return
				}

				let self = this
				uni.getLocation({
					type: 'wgs84',
					success: function (res) {
						let longitude = res.longitude
						let latitude =  res.latitude
						console.log('当前位置的经度：' + res.longitude);
						console.log('当前位置的纬度：' + res.latitude);

					
					},
					fail:function(err:any){
						let msg = JSON.stringify(err)
						console.log('定位报错：' + JSON.stringify(err));

					},
				});
			},
			clickHeader(){

				if(this.isLogin === false){
					(this as any).$refs.authpopup.open()
					return
				}
			},
			loginAction(){
				if(this.isLogin === false){
					(this as any).$refs.authpopup.open()
					return
				}
			},
			clickProtocol(){
				
				(this as any).$approuter.push('/subPackages/user/webview?type=login')


			},
			clickAgreeProtocol(){
             this.isAgree = !this.isAgree
			},
            authAction(){
				if(this.isAgree === false){
					(this as any).$toast.infoToast('请先阅读并同意相关协议')
					return
				}

				let self = this
				uni.login({
					provider: 'weixin', //使用微信登录
					success: function (loginRes) {
						console.log('微信授权结果：'+JSON.stringify(loginRes));

						let code =  loginRes.code
						if(code !== null && code !== ''){
							self.loginReq(code)

						}else{
							(self as any).$toast.infoToast(loginRes.errMsg)

						}
					},fail(result) {
						(self as any).$toast.infoToast(result.errMsg)
					},
				});

			},
			loginReq(authcode:string){//登录请求

				let param = {'js_code':authcode}
				let self = this;
				(this as any).$api.loginRequest(param).then(function(res:any){
					if(res.success){
						let token = res.data as any
						(self as any).$User.setToken(token);
						self.isLogin = true;


						self.loadData();
						self.loadUserInfoReq();
						(self as any).$refs.authpopup.close()
						self.startLocate()

						if(res.detail !== 'login'){

							setTimeout(() => {
								(self as any).$refs.popup.open()
							}, 300);
						}
						

					}
				})
			},
            notauthAction(){
				(this as any).$refs.authpopup.close()

            },
			
			hideUpdateUserPopView(){
				(this as any).$refs.popup.close()

			},
	        msgAction(){

				if(this.isLogin === false){
					(this as any).$refs.authpopup.open()
					return
				}
				(this as any).$approuter.push('/subPackages/msg/index')
			},
			addAction(){
				if(this.isLogin === false){
					(this as any).$refs.authpopup.open()
					return
				}

				let self = this;
				uni.showActionSheet({
					itemList: ['扫一扫添加设备', '手动输入添加设备'],
					success: function (res) {
						if(res.tapIndex === 0){
							self.clickScanAddDevice();
						}else if(res.tapIndex === 1){
							self.clickInputAddDevice();
						}
						
					},
					fail: function (res) {
						console.log(res.errMsg);
					}
				});


				
			},
			clickScanAddDevice(){
				uni.scanCode({
					success: function (res) {
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
						if(res.result === '' || res.result === null || res.result === undefined){
                             toast.infoToast('请检查二维码是否正常，再扫描添加')
						}else{
							console.log('扫描的编码：'+res.result )

							router.pushNative('/subPackages/device/addDevice?deviceId='+res.result,false);
						}
						
					}
				});

                //   this.isShowRightPop = true

			},
			clickInputAddDevice(){
				let placeholderStr =  "请输入设备编码";

				let self = this
				uni.showModal({
					title: '添加设备',
					editable:true,
					placeholderText:placeholderStr,
					cancelText:'取消',
					confirmText:'保存',
					success: function (res) {
						if (res.confirm) {
							let content = res.content as any

							if(content === '' || content === null || content=== undefined){
								toast.infoToast('请输入设备编码')
							}else{
								console.log('输入的编码：'+content)
								router.pushNative('/subPackages/device/addDevice?deviceId='+content,false);
							}
						
							
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					},

				});
			},
			uploadHead(e:any){

				let self = this
				let tmp =   e.detail.avatarUrl as any


				let param = {url:tmp}

				console.log('开始上传头像:'+JSON.stringify(e.detail));
				(this as any).$api.weixinUploadFile(param,(res:any) =>{

					self.tmpUser.avatarUrl = res
					self.$forceUpdate()
				});
			},
			bindblur(e:any){

				let tmp =   e.detail.value as any
				this.tmpUser.nickName = tmp
				this.$forceUpdate()

			},
			submitUpdateUserInfo(){

				if(this.tmpUser.avatarUrl === null || this.tmpUser.avatarUrl === undefined || this.tmpUser.avatarUrl === ''){

					(this as any).$toast.infoToast('请上传头像')
					return
				}
				if(this.tmpUser.nickName === null || this.tmpUser.nickName === undefined || this.tmpUser.nickName === ''){

					(this as any).$toast.infoToast('请输入昵称')
					return
				}

				let self = this;
				let nameParam = {'nickname':this.tmpUser.nickName};
				let picParam = {"head_portrait":this.tmpUser.avatarUrl};


				(this as any).$api.updateUserHeadpicRequest(picParam).then(function(res:any){
					(self as any).$api.updateUserNicknameRequest(nameParam).then(function(res:any){
						(self as any).$refs.popup.close()
						self.loadUserInfoReq()
					}).catch(function(error:any){
						(self as any).$refs.popup.close()
						self.loadUserInfoReq()

					});
				});

				


				
	 
			},
			loadUserInfoReq(){
				if(this.isLogin === false){
					this.user = null as any;
					this.list = [] as any;
					this.waringTipsMsg = ''
					this.company = {} as any;
					return
				}
				let self = this;
				(this as any).$api.queryUserinfoRequest().then(function(res:any){
					if(res.success){
						self.user = res.data
						self.$forceUpdate()
					}
				});


			},
			loadNewestWarningTipsReq(){
				if(this.isLogin === false){
					return
				}
				let self = this
				let param = {'pageindex':1,'pagesize':1};
				(this as any).$api.queryNewUnreadMsgRequest(param).then( (res:any)=>{
					if(res.success){

						if(res.data !== null ){

							if(res.data.length > 0){
                                let model = res.data[0]
								self.waringTipsMsg = model.mesagecontent
								self.isCloseWarningTips = false;
							}else{
								self.waringTipsMsg = ''
							}
						}else{
							self.waringTipsMsg = ''
						}


					}else{
						self.waringTipsMsg = ''
					}
					self.$forceUpdate()
				}).catch((err:any) => {
					self.waringTipsMsg = ''
				})
				// console.log('设备id:'+ (this as any).$User.currentConnectedEquipment.deviceID + '  蓝牙连接状态: '+(this as any).$User.isConnectedBlueTooth)

				// if((this as any).$User.currentConnectedEquipment.deviceID === '' || (this as any).$User.isConnectedBlueTooth === false){
				// 	return
				// }

				// let deviceID = (this as any).$User.currentConnectedEquipment.deviceID;
				// // let deviceID = '5608'
				// let param = {deviceid:deviceID}
				// let self = this;
				// (this as any).$api.queryNewMaintainTipRequest(param).then(function(res:any){
					// if(res.success){
					// 	self.waringTipsMsg = res.data.MessageTitle
					// 	self.isCloseWarningTips = false;
					// }else{
					// 	self.waringTipsMsg = ''
					// }
				// })
			},
			hiddenRightNaviPopView(){
				this.isShowRightPop = false
			},
			clickRightNaviItem(title:string){
				
				// this.isShowRightPop = false
				// let self = this;
				// (self as any).$approuter.push('/subPackages/device/addDevice?deviceId='+'123');

				// return;
				// 允许从相机和相册扫码
				uni.scanCode({
					success: function (res) {
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
						if(res.result === '' || res.result === null || res.result === undefined){
                             (self as any).$toast.infoToast('请检查二维码是否正常，再扫描添加')
						}else{
							(self as any).$approuter.push('/subPackages/device/addDevice?deviceId='+res.result);
						}
						
					}
				});

			},
	
			clickEquipOperate(title:string){
				let self = this

				if(this.choosedEquip.actStatus === null || this.choosedEquip.actStatus === undefined){
						this.choosedEquip.actStatus = false as any;
					}

				if(title === '连接蓝牙'){
					(this as any).$User.tempChoosedEquipDeviceId =  this.choosedEquip.deviceID as any



			


					(this as any).$User.currentTempChoosedEquipment = this.choosedEquip;
					
					console.log('进入连接的设备名称：'+(this as any).$User.tempChoosedEquipDeviceName);

					(this as any).$approuter.push('/subPackages/bluetooth/bluetoothList')

				}else if(title === '断开蓝牙'){



					uni.showModal({
                                    title: '提示',
                                    content: '是否确认断开蓝牙连接？',
                                    confirmText:'确认',
									cancelText:'取消',
                                    success: function (res) {
										if (res.confirm) {
											
											uni.closeBluetoothAdapter({
												success(res) {
													(self as any).$User.isConnectedBlueTooth = false;
														(self as any).$User.isTempConnectedBlueTooth = false;
													btViewmodel.uploadBlueToothStatusData()

														self.choosedEquip = null as any;
														self.list.forEach((element:any) => {
															element.isConnect = false
														});
														
														(self as any).$User.currentConnectedEquipment.deviceID = '';
														(self as any).$User.currentConnectedBlueTooth = {} as any
														self.$forceUpdate()

												}
											})

										}
                                    }
                                });

					
					
					
				}else if(title === '删除设备'){
					let equip = this.choosedEquip
					uni.showModal({
                                    title: '提示',
                                    content: '是否确认删除设备 '+equip.deviceName,
                                    confirmText:'确认',
									cancelText:'取消',
                                    success: function (res) {
										if (res.confirm) {
											self.deleteEquipmentReq(equip)
										}
                                    }
                                });
				} else if(title === '操作设备'){
					(this as any).$User.choosedShowDetailEquip = this.choosedEquip as any
					(this as any).$User.isShowIntoDeviceLoading = true;
					(this as any).$approuter.push('/subPackages/device/detail');
				}

				(this as any).$refs.qdxPop.close();

			},
			closeCompanyAction(){
				this.isCloseCompanyView = true
			},
			closeWarnMsgAction(){
				this.isCloseWarningTips = true
			},
			editAction(){
				// (this as any).$refs.popup.open()
				if(this.isLogin === false){
					(this as any).$refs.authpopup.open()
					return
				}
				(this as any).$approuter.push('/subPackages/user/index')


			},
			clickDetail(e:any){


				const itemId = e.target.dataset.id;
				let equip = this.list[itemId];
				this.choosedEquip = equip;
				if((this as any).$User.currentConnectedEquipment.deviceID !== '' && (this as any).$User.isConnectedBlueTooth){
					if(equip.deviceID === (this as any).$User.currentConnectedEquipment.deviceID){
						this.operateList = ['操作设备','断开蓝牙'] as any
					}else{
						this.operateList = ['连接蓝牙','删除设备'] as any
					}
				}else{
					this.operateList = ['连接蓝牙','删除设备'] as any
				}
				(this as any).$refs.qdxPop.open(e);

				

				// if((this as any).$User.isConnectedBlueTooth === false || (this as any).$User.currentConnectedEquipment.deviceID !== item.deviceID){
				// 	(this as any).$toast.infoToast('请长按设备进行蓝牙连接后，再点击进入设备操控')
				// 	return
				// }
				// (this as any).$User.choosedShowDetailEquip = item as any

				// console.log('当前联机的设备id:'+(this as any).$User.choosedShowDetailEquip.deviceID);
				// console.log('当前token:'+(this as any).$User.getToken());

				// (this as any).$approuter.push('/subPackages/device/detail');

			},
			longTapEquip(e:any){
				// const itemId = e.target.dataset.id;
				// let equip = this.list[itemId];
				// this.choosedEquip = equip;

				// if((this as any).$User.currentConnectedEquipment.deviceID !== '' && (this as any).$User.isConnectedBlueTooth){
				// 	if(equip.deviceID === (this as any).$User.currentConnectedEquipment.deviceID){
				// 		this.operateList = ['断开蓝牙'] as any
				// 	}else{
				// 		this.operateList = ['连接蓝牙','删除设备'] as any
				// 	}
				// }else{
				// 	this.operateList = ['连接蓝牙','删除设备'] as any
				// }
				

				// (this as any).$refs.qdxPop.open(e);

			},
			deleteEquipmentReq(model:any){
				let self = this
				let param = {'deviceid':model.deviceID};
				(this as any).$api.deleteEquipmentRequest(param).then(function(res:any){

					if(res.success){
						(self as any).$toast.infoToast('删除成功')
						self.loadData()

						
					}
				});
             
			},
			loadData(){
				if(this.isLogin === false){
					return
				}
				
				this.list = [] as any;
		
				let self = this
				let param = {};
				(this as any).$api.queryMyEquipmentListRequest(param).then(function(res:any){

					if(res.success){
						self.list = res.data
						
						///刷新蓝牙选中状态
						self.refreshListDeviceConnectStatus()
					

						
					}
				});

			},
			refreshListDeviceConnectStatus(){
				let companyInfo = null

			

				if((this as any).$User.currentConnectedBlueTooth.deviceId !== undefined  && (this as any).$User.currentConnectedBlueTooth.deviceId !== '' && (this as any).$User.isConnectedBlueTooth){
					this.list.forEach((element:any) => {
						if(element.deviceID === (this as any).$User.currentConnectedEquipment.deviceID){

							element.isConnect = true
							companyInfo = element.companyInfo
						}else{
							element.isConnect = false
						}
					});
				}else{
					this.list.forEach((element:any) => {
						element.isConnect = false
					});
				}
				if(companyInfo === null && this.list.length > 0){
					companyInfo = this.list[0].companyInfo
				}

				this.company = companyInfo
				this.isHasCompanyDesc = this.company !== null && (this.company.companyDesc !== null || this.company.companyDesc !== undefined)


				this.$forceUpdate();



				if(this.company === null || this.company.companyDesc === null || this.company.companyDesc === undefined){
					return;
				}
				if(this.company.companyDesc.length > 150){
					this.showAll = false;
				}else{
					this.showAll = true;
				}

			
			}
			
		}
	});
</script>

<style lang="scss" scoped>
.container {
		// color: #eaeaea;
		width: 100%;

		.bg{
			position: fixed;
			width: 100%;
			height:100vh;
			z-index:-1;
			top:0;
			left:0;
			background:linear-gradient(to bottom,rgba(228,237,244,1) 100%,rgba(244,245,246,1) 100%);

		}
		.content{
			padding: 0px 18px;
			width: calc(100% - 18px * 2);
		}
    .add-content {
		margin-left: 0;
		width: calc(100% + 5px);

       .add-btn{
		width: 35px;
		height: 35px;
			.add {
				width: 23px;
				height: 23px;
			}
	   }
    }
    .tp {
		width: 100%;
        .avatar {
			width: 44px;
			height: 44px;
			border: 1px solid white;
			border-radius: 30px;
			margin-top: 5px;
        }
        .tp-info {
			margin-left: 15px;
			// width: calc(100% - 15px - 44px);

			.login-name{
				font-size: 16px;
				color: #284D8D;
				font-weight: bold;
				font-family: PingFangSC, PingFang SC;
			}

			.login-arrow{
				width: 10px;
				height: 10px;
				margin-left: 3px;
			}

            .tp-name-content {
				width: 100%;
                .user-name {
					font-size: 15px;
                }
                .edit-btn {
					width: 40px;
					height: 40px;
                    .edit {
						width: 18px;
						height: 18px;
                    }
                }
            }
            .machine-count {
				margin-top: 0px;
				font-size: 13px;
				color:#787878;

            }
        }
    }

	.warn-content{
		margin-top: 20px;

		background-color: #FFECE9;
		border-radius: 12px;
		padding:10px 15px 15px 15px;
		width: calc(100% - 15px * 2);

		.warn-text{
			color:#DF3D3D;
			font-size: 14px;
			width: calc(100% - 60px);

		}
		.close-btn {
				width: 30px;
				height: 30px;
				margin-right: -15px;
                .close {
					width: 15px;
					height: 15px;
                }
            }
	}
    .mid {
		margin-top: 20px;

		background-color: white;
		border-radius: 12px;
		padding:10px 15px 15px 15px;
		width: calc(100% - 15px * 2);

		
        .mid-tp {
			width: 100%;

            .company-name {
				width: calc(100% - 60px);
				margin-top: 5px;
            }
            .close-btn {
				width: 30px;
				height: 30px;
				margin-right: -15px;
                .close {
					width: 15px;
					height: 15px;
                }
            }
        }
		.company-desc{
			margin-top: 7px;
			
			

			.showAll {
				margin-top: 15px;
				// 展开收缩按钮居中
				text-align: center;
				color:#777777;
				font-size:14px;
				.pullicon{
					width: 12px;
					height: 12px;
					margin-left: 5px;
				}
				
			}

			.qyjs {
				display: -webkit-box; //将对象作为弹性伸缩盒子模型显示
			}

			.showAllQyjs {
				display: -webkit-box; //将对象作为弹性伸缩盒子模型显示
				overflow: hidden; //超出部分隐藏
				-webkit-line-clamp: 5; //显示几行
				text-overflow: ellipsis; //超出部分显示省略号
				-webkit-box-orient: vertical;
			}


			.company-desc-text{
				line-height: 20px;
				size: 12px;
				color: #999999;
			}
		}
    }


    .bt {
		width: 100%;
		.section{
			margin-left: 10px;
		}
		.no-data-voew{
			width: 100%;
			margin-top: 90px;
			.no-data-icon{
				width: 187px;
				height: 93px;
			}
			.tips-text{
				font-size: 12px;
				color:#38393A;
			}
		}
        .list {
			width: 100%;
			margin-top: 10px;

			.item-left{

			}

			.item-right{
				margin-left: 12px;
			}
            .item {
				background-color: white;
				padding: 10px;
				border-radius: 12px;
				width: calc((100% - 12px) / 2.0 - 10px * 2);
				margin-bottom: 12px;

                .item-tp {
					width: 100%;
                    .item-name {
						font-size: 14px;
						width: calc(100% - 20px);
                    }
                    .connect {
						width: 13px;
						height: 13px;
                    }
                }
                .status-name {
					margin-top: 2px;
					font-size: 12px;
                }
				.tag-name{
					padding: 2px 3px;
					font-size: 10px;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					color: #284D8D;
					text-align: center;
					border: 1px solid #284D8D;
					border-radius: 4px;
					background: #F5F7FA;


				}
                .status-green {
					color: green;
                }
                .status-red {
					color: red;

                }
                .equip-img {
					margin-top: 10px;
					width: 60px;
					height: 60px;
                }
            }
        }
    }


	.rightmask{
		position: fixed;
        width: 100%;
		height: 100vh;
		top: 0px;
		left: 0px;
		background-color: rgba($color: #000000, $alpha: 0.3);
		.rightpop{
			margin-top: 35px;
			margin-right: 20px;
			padding: 8px 15px;
			background-color: white;
			border-radius: 12px;
			overflow: hidden;
			height: 65px;

			.right-item{
				// height: 40px;
				// line-height: 40px;
				padding: 8px 0 ;
				width: 80px;
				font-size: 13px;
				color: #000000;
				margin-bottom: 0px;
			}
		}
	}

	.operatelist{
			padding: 8px 15px;
			background-color: white;
			border-radius: 8px;
			overflow: hidden;
			// height: 100px;

			.operate-item{
				padding: 8px 0 ;
				width: 80px;
				font-size: 13px;
				color: #000000;
				margin-bottom: 0px;
			}
	}

	.authpopview{
            padding-left: 25px;
			padding-right: 25px;
            width: calc(100% - 25px * 2);

			background-color: white;
			border-top-left-radius: 20px;
			 border-top-right-radius: 20px;

			.skip-btn{
				margin-right: -15px;
                width: 40px;
                height: 40px;
                .skip{
                    width: 20px;
                }
            }

	

			.logo{
					margin-top: 0px;
					width: 120px;
					height: 60px;
				}

			.title{
				margin-left: 0px;
				color: black;
				font-size: 18px;
				font-weight: 500;
				margin-top: 30px;
	
			}
			.slogan{
				margin-top: 5px;
				margin-left: 0px;
				color: black;
				font-size: 18px;
				font-weight: 500;
			}


			.line{
				width: 100%;
				height: 1px;
				background-color: #e6e6e6;
				margin-top: 18px;
			}
			

			.needtips{
				margin-left: 0px;
				font-size: 15px;
				margin-top: 15px;
				color:#666666;
			}

			.defualt-btn{
            width: calc(100% - 0px * 2);
            margin: 0 30px 0 0px;
            height: 50px;
            .btn-icon{
                width: 16px;
                height: 16px;

            }
            .btn-name{
                font-size: 14px;
                color: #888888;
                margin-left: 7px;
            }
        }
        .btns{
                width: 100%;
				margin-top: 30px;
				z-index:2;
				margin-bottom: 30px;
                .auth-btn{
                    width: 70%;
                    line-height: 40px;
					height: 40px;
					background-color: #284D8D;
					border-radius: 25px;
					font-size: 14px;
					color: white;
					text-align: center;
					
                    
                }

                .notauth-btn{
                    margin-top: 15px;
					line-height: 40px;
					height: 40px;
                    width: 70%;
					font-size: 14px;
					color: #284D8D;;
					text-align: center;
    
                }
            }
    }

	.popup{
			width: 100%;
			padding-bottom: 40px;
			height: 300px;
			background-color: white;
			border-top-left-radius: 20px;
			 border-top-right-radius: 20px;



			 .skip-btn{
				margin-top:10px;

				margin-right: 15px;
                width: 40px;
                height: 40px;
				margin-bottom: 20px;
                .skip{
                    width: 20px;
                }
            }


			.title{
				color: black;
				font-size: 18px;
				font-weight: 500;
			}
			.text{
				color: black;
				font-size: 18px;
				font-weight: 500;

			}

			.info{


				.label{
				//    width: 100px;
				color: black;
				font-size: 15px;
				}

				.line{
					margin-left: -20px;
					margin-right: -20px;
					background-color: #f6f6f6;
					margin-top: 20px;
					height: 1px;
				}

				.headBtn{

					.head-pic{
						width: 44px;
						height: 44px;
						border-radius: 30px;
					}
				}


				.input-cont{
					margin-left: 20px;
						width: 120px;
						height: 40px;
						// border: 1px solid #e4e4e4;
						border-radius: 4px;
						padding: 0 10px;

					.nickname{
						width: 100%;
						height: 100%;
						background-color: white !important;
						
					}
				}
				

		
			}

			.popbtns{
				margin-top: 20px;
				padding: 10px 20px;
				width: calc(100% - 20px * 2);
				.btn{
					width: 120px;
					height: 40px;
					line-height: 40px;
					text-align: center;
					border-radius: 20px;
				}

				.cancel-btn{
					border: 1px solid #CED0D1;
					color:black;
				}
				.save-btn{
					background-color: #284D8D;
					color: white;

				}
			}
		}

		.headBtn{
			border-radius: 40px !important;
		}

		.mt-80{
			margin-top: 80px;
		}

		.guide-mask{
			position: fixed;
			width: 100%;
			height: 100vh;
			z-index:99;
			background-color: rgba($color: #000000, $alpha: 0.8);

			.guide1{
				margin-top: 40px;
				margin-left:10px;
				width: 142px;

			}
			.guide2{
				margin-top: 0px;
				margin-left:calc(100% - 82px);
				width: 82px;
				height:83px
				
			}
			.guide3{
				margin-top: 150px;
				margin-left:10px;
				width: calc(100% - 10px * 2);
				
			}

		

			.guide-tips{
				margin-top: 5px;
				margin-left: 20px;
				margin-right: 20px;
				width: calc(100% - 20px * 2);
				color:white;
				font-size: 17px;
				font-weight: 400;
		
			}

			.g-tips3{
				padding: 0 15px;
				width: calc(100% - 20px * 2 - 15px * 2);
			}

			.guide-btn-con{
				width: 100%;
				.guide-btn{
					width: 108px;
					height: 36px;
					line-height: 36px;
					border-radius: 4px;
					background-color: #306DCF;
					text-align: center;
					color: white;
					font-size: 14px;

				}

			}
			.g-btn1{
				margin-top: 50px;
			}
			.g-btn2{
				margin-top: 50px;
			}
			.g-btn3{
				margin-top: 30px;

			}



		}

	
	}
</style>
